package com.project.hqshorttaxi.service.impl;

import com.project.hqshorttaxi.dto.DiscountParam;
import com.project.hqshorttaxi.entity.DiscountNum;
import com.project.hqshorttaxi.mapper.DiscountNumMapper;
import com.project.hqshorttaxi.service.DiscountService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DiscountServiceImpl implements DiscountService {

    @Resource
    private DiscountNumMapper discountNumMapper;

    @Override
    public DiscountNum getById(Integer id) {
        return discountNumMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<DiscountNum> list(DiscountParam param) {
        Example example = new Example(DiscountNum.class);
        Example.Criteria c = example.createCriteria();
        if (!StringUtils.isEmpty(param.getPlateNumber())) {
            c.andLike("plateNumber", "%" + param.getPlateNumber() + "%");
        }
        if (param.getBeginTime() != null) {
            c.andGreaterThanOrEqualTo("discountDate", param.getBeginTime());
        }
        if (param.getEndTime() != null) {
            c.andLessThanOrEqualTo("discountDate", param.getEndTime());
        }
        example.orderBy("discountDate").desc();
        List<DiscountNum> list = discountNumMapper.selectByExample(example);
        return list;
    }
}
